home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / game / think / AmiChess.lha / AmiChess / src / ttable.c < prev    next >
C/C++ Source or Header  |  2002-10-31  |  2KB  |  82 lines

  1. #include <string.h>
  2. #include "common.h"
  3.  
  4. void TTPut(short side,short depth,short ply,int alpha,int beta,int score,int move)
  5. {
  6. HashSlot *t;
  7. depth=depth/DEPTH;
  8. t=HashTab[side]; 
  9. t+=((HashKey&TTHashMask)&-2);
  10. if(depth<t->depth&&!MATESCORE(score)) t++;
  11. else if(t->flag&&t->key!=KEY(HashKey)) *(t+1)=*t;
  12. if(t->flag) CollHashCnt++;
  13. TotalPutHashCnt++;
  14. t->move=move;
  15. t->key=KEY(HashKey);
  16. t->depth=depth;
  17. if(t->depth==0) t->flag=QUIESCENT;
  18. else if(score>=beta) t->flag=LOWERBOUND;         
  19. else if(score<=alpha) t->flag=UPPERBOUND;
  20. else t->flag=EXACTSCORE;
  21. if(MATESCORE(score)) t->score=score+(score>0?ply:-ply);
  22. else t->score=score;
  23. }
  24.  
  25.  
  26. short TTGet(short side,short depth,short ply,int alpha,int beta,int *score,int *move)
  27. {
  28. HashSlot *t;
  29. KeyType Key;
  30. TotalGetHashCnt++;
  31. t=HashTab[side]; 
  32. t+=((HashKey&TTHashMask)&-2);
  33. Key=KEY(HashKey);
  34. if(Key!=t->key&&Key!=(++t)->key) return 0;
  35. depth=depth/DEPTH;
  36. GoodGetHashCnt++;
  37. *move=t->move;
  38. *score=t->score;
  39. if(t->depth==0) return QUIESCENT;
  40. if(t->depth<depth&&!MATESCORE(t->score)) return POORDRAFT;
  41. if(MATESCORE(*score)) *score-=(*score>0?ply:-ply);
  42. return t->flag;
  43. }
  44.  
  45. short TTGetPV(short side,short ply,int score,int *move)
  46. {
  47. HashSlot *t;
  48. KeyType Key;
  49. int s;
  50. t=HashTab[side]; 
  51. t+=((HashKey&TTHashMask)&-2);
  52. Key=KEY(HashKey);
  53. s=t->score;
  54. if(MATESCORE(s)) s-=(s>0?ply:-ply);
  55. if(Key==t->key &&((ply&1&&score==s)||(!(ply&1)&&score==-s)))
  56.     {
  57.     *move=t->move;
  58.     return 1;
  59.     }
  60. t++;
  61. s=t->score;
  62. if(MATESCORE(s)) s-=(s>0?ply:-ply);
  63. if(Key==t->key &&((ply&1&&score==s)||(!(ply&1)&&score==-s)))
  64.     {
  65.     *move=t->move;
  66.     return 1;
  67.     }
  68. return 0;
  69. }
  70.  
  71. void TTClear()
  72. {
  73. memset(HashTab[white],0,HashSize*sizeof(HashSlot));
  74. memset(HashTab[black],0,HashSize*sizeof(HashSlot));
  75. }
  76.  
  77. void PTClear()
  78. {
  79. memset(PawnTab[white],0,PAWNSLOTS*sizeof(PawnSlot));
  80. memset(PawnTab[black],0,PAWNSLOTS*sizeof(PawnSlot));
  81. }
  82.